package com.ethan.cj.ssm.service.impl;

import com.ethan.cj.ssm.dao.CreditGrantingDao;
import com.ethan.cj.ssm.entity.CreditGranting;
import com.ethan.cj.ssm.service.CreditGrantingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 授信机构逻辑处理层接口的实现
 */
@Service
public class CreditGrantingServiceImpl implements CreditGrantingService {

    /**
     * 授信机构dao层映射
     */
    @Autowired
    private CreditGrantingDao cgd;

    /**
     * 查询全部机构信息
     * @return 机构集合
     */
    @Override
    public Map<Object, Object> selectCreditGranting() {
        List<CreditGranting> list = cgd.selectCreditGranting();
        Map<Object,Object> result = new HashMap<>();
        if (list != null && list.size() > 0) {
            result.put("code", 0);
            result.put("msg", "");
            result.put("data", list);
        } else {
            result.put("code", 1);
            result.put("msg", "无数据");
        }
        return result;
    }

    /**
     * 根据ID查询授信机构信息
     * @param cgid 查询条件
     * @return 授信机构对象
     */
    @Override
    public CreditGranting selecteByCgid(int cgid) {
        return cgd.selecteByCgid(cgid);
    }
}
